2. Getting Started



This chapter gives you a brief overview of Java in CodeWarrior, installation, system requirements and tools available to you.

This chapter includes the following topics:


System Requirements

If you can run CodeWarrior, you can target the Java virtual machine.


Windows Requirements

The Windows-hosted version of CodeWarrior requires the following:


Mac OS Requirements

The Mac OS-hosted version of CodeWarrior requires the following:


Solaris Requirements

The Solaris-hosted version of CodeWarrior requires the following:


Installing CodeWarrior for Java

Use the CodeWarrior installer application to install the CodeWarrior IDE. Be sure to follow the instructions in the installer application. The installer ensures that everything is installed in the proper locations.

See the QuickStart manual for instructions on using the installer to install CodeWarrior on your particular platform.


Overview of Java in CodeWarrior

Java is both a programming language and, in a virtual sense, a computer platform-a target, in CodeWarrior terminology. As such, Java is unique among the languages and targets supported in the CodeWarrior IDE. You can think of Java as not only a language, but as an instruction set for the Java virtual machine.

The virtual machine, commonly called a VM, is an abstract computer microprocessor. Like any silicon computer chip, the virtual machine has an instruction set. The instructions for the Java virtual machine are called bytecodes.

A bytecode is a stream of formatted bytes that has a precisely defined impact on the virtual machine. Bytecodes tell the virtual machine to do things like push and pop values on a stack, branch, load and store values, and so forth. Just like traditional assembly language instructions affect a silicon-based processor, the Java bytecodes are a real instruction set for the Java virtual machine.

The reason for the abstract nature of the virtual machine and its bytecode instruction set is to allow you, the programmer, to create platform-independent code. The runtime interpreter and just-in-time compilers replicate in a real operating system the effect that a bytecode has on the virtual machine.

What you do in the Java environment is a little different from what you have done in the past using C, C++, or Pascal.

The development process for Java software in CodeWarrior has the following basic steps:

1. Write source code.

In CodeWarrior, you write Java source code in exactly the same way you do for C, C++, and Pascal. You use the same project manager and the same source code editor. You get all the power and features of CodeWarrior. To target the Java virtual machine, you make the appropriate selection in the proper settings panel.

2. Compile the source code.

Again, this process is exactly like it is for any language and target supported in CodeWarrior. You issue the appropriate Compile or Make command from the CodeWarrior Project menu. In response, the CodeWarrior Java compiler generates Java bytecodes based on your source code. CodeWarrior saves the bytecodes in a Java class file.

The bytecodes in the Java class file are analogous to the object code generated by a C/C++ or Pascal compiler. The difference between traditional object code and Java bytecodes is in how they run.

Object code can run directly on the platform for which it was compiled, but cannot run on any other platform. You must compile it over and over again for each platform. There are also serious cross-platform problems you can encounter trying to address multiple operating systems and computer microprocessors.

Figure 2.1 Compiling and running object code


Java bytecodes cannot run directly on any real machine. On the other hand, the Java bytecodes created by the CodeWarrior Java compiler can be interpreted to run on any platform that has a bytecode interpreter (BCI). You write the code once, compile it once, and then you are done.

Figure 2.2 Compiling and running Java bytecodes


3. Run the code.

Choose Project > Run and CodeWarrior launches the applet with the applet viewer chosen in Target Settings. To learn how to specify an applet viewer, see "Target Settings." Remember, the bytecodes in the class file cannot run directly on any real platform. The class file must be run under the control of a bytecode interpreter (BCI). The BCI is responsible for translating the bytecodes into machine-native instructions.

4. Debug the code with the CodeWarrior Debugger.

The final step in the development process is to test and debug your code. You debug Java code using the same CodeWarrior debugger you use for C/C++ and Pascal code. The CodeWarrior debugger understands Java. The debugger does everything you would expect the debugger to do. It has a stack crawl, displays local variables, and allows you to set breakpoints.

To debug Java code, your applet or application must be built to include debugging information. First choose Project > Enable Debugger to enable the debugger. Then click the debug column in the project window next to the file you want to debug to tell the IDE to include debugging information when it compiles the file. Choose Project > Make to compile and link your code. You can also choose Project > Debug menu. CodeWarrior compiles, links, and launches your program under debugger control.

From here you can set break points, and run your program.


Summary

That is all there is to it. As you can see, the big difference between Java and compiled languages is that Java code is interpreted at runtime.

If you have used CodeWarrior in the past, developing Java code in CodeWarrior is going to look very familiar to you. If you are new to CodeWarrior, you will find developing Java code to be a pleasure once you master the tools.


Development Tools for Java

These are the tools CodeWarrior provides for developing Java software:


CodeWarrior IDE

The CodeWarrior Integrated Development Environment (IDE) provides a complete set of tools for developing application programs for a variety of target platforms, including 68K- and PowerPC-based Mac OS systems, Win32/x86 systems, Solaris, and Java. You use the same IDE when developing code for all target platforms; you designate the platform and code generator of your choice when you create your project.

For information on the CodeWarrior IDE, see the IDE User Guide.


CodeWarrior RAD Tools

CodeWarrior RAD tools let you visually construct an application. The tools included with the IDE are for use with C++ and Java. They extend the graphical capabilities of the IDE for use with RAD.

For more information on CodeWarrior RAD tools, see the IDE User Guide.


Java Linker

Like the compilers, the Java Linker is a plug-in tool integrated into the CodeWarrior IDE.


CodeWarrior Debugger

The CodeWarrior debugger controls your program's execution and allows you to see what is happening internally as your program runs. You use the debugger to find problems in your program's execution.

The debugger can execute your program one statement at a time, and suspend execution when control reaches a specified point. When the debugger stops a program, you can view the chain of function calls, examine and change the values of variables, and inspect the contents of the processor's registers.

For general information about the debugger, including all of its common features and its visual interface, you should read the IDE User Guide.

For more information about debugging software for Java, see "Debugging Java Projects."


Java API Headers

The Java Application Programming Interface (API) is a set of data structures and functions used to interface to the Java operating system.


JavaDoc

JavaDoc is a batch compiler that processes Java source code files, and uses the comments preceding classes, methods, etc. to generate HTML based documentation for the code. See "JavaDoc" for more information.





Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: support@metrowerks.com
Copyright © 1999, Metrowerks Corp. All rights reserved.

Last updated: May 24, 1999 * Chris Magnuson * John Roseborough